package com.henau.lx.controller;

import com.henau.lx.pojo.User;
import com.henau.lx.service.UserService;
import com.henau.lx.service.impl.UserServiceImpl;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

public class GetUserServiceServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("测试。。。");
        WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        UserService userService = context.getBean("userServiceImpl", UserService.class);
        System.out.println(userService);
        System.out.println("1");
        List<User> userByName = userService.findUserByName();
        System.out.println(userByName);
        request.setAttribute("lists",userByName);
        request.getRequestDispatcher("list.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
